package com.itheima.web.servlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/*
获取文件的真实路径
 */
@WebServlet("/responseServlet04")
public class ResponseServlet04 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          //获取上下文对象
        ServletContext servletContext = request.getServletContext();
        //获取a.txt的真实路径
        String realPath = servletContext.getRealPath("a.txt");
        System.out.println(realPath);//\IdeaProjects\java_web2\day15_response\target\day15_response-1.0-SNAPSHOT\a.txt
        //获取b.txt文件的真实路径
        String realPath1 = servletContext.getRealPath("/WEB-INF/classes/b.txt");
        System.out.println(realPath1);//D:\IdeaProjects\java_web2\day15_response\target\day15_response-1.0-SNAPSHOT\WEB-INF\classes\b.txt
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
